<template>
  <div>
    <div v-show="!isShowDetail">
      <jxf-titletip :title="title" @refreshPage="refreshFuc"></jxf-titletip>
      <el-card class="mt20">
        <el-form :inline="true" :model="searchInfo" ref="searchInfo">
          <el-form-item label="供应商企业名:" prop="enterpriseName">
            <el-input v-model.trim="searchInfo.enterpriseName" clearable @keyup.enter.native="enterNextInput('telphone')" ref="input-enterpriseName"></el-input>
          </el-form-item>
          <el-form-item label="供应商账号:" prop="telphone">
            <el-input v-model.trim="searchInfo.telphone" clearable @keyup.enter.native="enterNextInput('shopName')" ref="input-telphone"></el-input>
          </el-form-item>
          <el-form-item label="供应商门店名称:" prop="shopName">
            <el-input v-model.trim="searchInfo.shopName" clearable @keyup.enter.native="onSearch" ref="input-shopName"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSearch()">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="info" @click="resetForm('searchInfo')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <el-card class="jxf-table-card mt20">
        <div slot="header" class="clearfix">
          <span>数据列表</span>
          <div>
            <el-button type="primary" @click="exportExcel" :loading="isSuccess">导出</el-button>
          </div>
        </div>
        <jxf-table class="" :table="dataTable">
          <template slot="totalAmount" slot-scope="supplier">
            <div>
              <div>￥{{supplier.row.totalAmount && supplier.row.totalAmount != 0 ? formatMoney.twoDecimal(supplier.row.totalAmount) : '0.00'}}</div>
            </div>
          </template>
          <template slot="operation" slot-scope="supplier">
            <div>
              <el-button type="text" @click="watchDetail(supplier.row)">查看详情</el-button>
            </div>
          </template>
        </jxf-table>
      </el-card>
      <jxf-pagination class="mt20" :pageTotal="pageTotal" :currentPage.sync='currentPage' :pageSize.sync="pageSize"
                      @currentPageChange="currentPageChange" @pageSizeChange="pageSizeChange"></jxf-pagination>
    </div>
    <ReceivablesDetail v-if="isShowDetail" :dataInfo="dataInfo" @goBack="goBack"></ReceivablesDetail>
  </div>
</template>

<script>
  import ReceivablesDetail from './components/ReceivablesDetail'
  import formatMoney from '@/assets/js/formatMoney'
    export default {
        name: "SupplierStatistics",
        components: { ReceivablesDetail },
        data() {
          return {
            title: "供应商应收未收统计",
            searchInfo: {
              enterpriseName: "",
              shopName: "",
              telphone: ""
            },
            dataInfo: {},
            formatMoney: formatMoney,
            isShowDetail: false,
            isSuccess: false,
            dataTable: {
              border:true,
              loading:false,
              hasSelect:false,
              hasOperation:false,
              tr: [
                {
                  id: '1',
                  minWidth: '140',
                  label: '供应商企业名称',
                  fixed: "left",
                  prop: 'enterpriseName'
                },
                {
                  id: '2',
                  minWidth: '140',
                  label: '供应商门店名称',
                  prop: 'shopName'
                },
                {
                  id: '3',
                  width: '120',
                  label: '供应商主体账号',
                  prop: 'telphone'
                },
                {
                  id: '4',
                  minWidth: '100',
                  label: '未收订单数',
                  prop: 'count'
                },
                {
                  id: '5',
                  minWidth: '160',
                  label: '未收订单总额（元）',
                  prop: 'totalAmount',
                  show: 'template'
                },
                {
                  id: '6',
                  label: '操作',
                  show: 'template',
                  fixed: "right",
                  width: "120",
                  prop: 'operation'
                }
              ],
              operation: [],
              data: []
            },
            pageTotal:0,
            pageSize:10,
            currentPage:1
          }
        },
        methods: {
          // 导出
          exportExcel() {
            this.isSuccess = true;
            let data = {
              ...this.searchInfo
            }
            ajax.export(apis.finance.exportSupplierStatisList, data).then((res) => {
              this.isSuccess = false;
              if(res.code) {
                if(res.code === "10000000") {

                } else {
                  this.$message.error(res.message)
                }
              }
            })
          },
          enterNextInput(inputName) {
            this.$refs["input-" + inputName].focus();
          },
          refreshFuc() {
            this.resetForm('searchInfo')
            this.currentPage = 1;
            this.pageSize = 10
            this.getData()
          },
          goBack() {
            this.isShowDetail = false;
          },
          getData() {
            this.dataTable.loading = true;
            let data = {
              ...this.searchInfo,
              page: this.currentPage,
              pageSize: this.pageSize
            };
            ajax.post(apis.finance.getSupplierStaticticList, data).then(res => {
              if(res.code === "10000000") {
                this.dataTable.data = res.data.dataList;
                this.pageTotal = res.data.total
              } else {
                this.$message.error(res.message)
              }
              this.dataTable.loading = false;
            })
          },
          onSearch() {
            this.currentPage = 1;
            this.getData()
          },
          resetForm(formName) {
            this.$refs[formName].resetFields()
          },
          // 切换页面
          currentPageChange(pageNo) {
            this.currentPage = pageNo,
            this.getData()
          },
          // 切换页面条数
          pageSizeChange(pageNo) {
            this.pageSize = pageNo
            this.getData()
          },
          // 查看详情
          watchDetail(obj) {
            let data = {
              ...obj,
              page: 1,
              pageSize: 10
            }
            ajax.post(apis.finance.getSuppierStaticticDetail, data).then(res => {
              if(res.code == "10000000") {
                this.dataInfo = res.data;
                this.dataInfo.supplyId = obj.supplyId
                this.dataInfo.enterpriseName = obj.enterpriseName
                this.isShowDetail = true;
              } else {
                this.$message.error(res.message)
              }
            })
          }
        },
        created() {
          this.onSearch()
        }
    }
</script>

<style lang="scss" scoped>

</style>
